﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ribbon.Core
{
    public class RibbonSplitPage : RibbonPageBase
    {
        public RibbonSplitPage()
        {
            this.BackColor = Color.FromArgb(209, 209, 209);
        }

        /// <summary>
        /// this componet's container
        /// </summary>
        private Ribbon parent;

        public override Ribbon Parent
        {
            get
            {
                return parent;
            }
            set
            {
                parent = value;

                if (this.Font == null)
                    this.Font = this.Parent.Font;

                GetSize();
            }
        }

        public override string ToString()
        {
            return string.Format("Name:{0} IsActive:{1}", this.Name, this.IsActive);
        }

        internal virtual void Refresh()
        {
            this.Parent.Refresh();
        }

        internal override void GetSize()
        {
            if (this.parent != null)
            {
                int height = parent.TabHeight - 8;

                if (height < 1)
                {
                    height = 20;
                }

                if (this.parent.TabHeight < height)
                {
                    this.parent.TabHeight = height;
                }

                float y = (this.parent.TabHeight - height) / 2f;

                this.Rect = new Rect(this.parent.TempEmptyX, y, 2f, height);

                this.parent.TempEmptyX += this.Rect.Width + 2f;
            }
        }

        public override void OnPaint(System.Drawing.Graphics g)
        {
            if (this.Rect == null)
            {
                throw new Exception("none region");
            }

            using (Pen p = new Pen(this.BackColor, 1f))
            {
                g.DrawLine(p, (int)this.Rect.X, (int)this.Rect.Y, (int)this.Rect.X, (int)(this.Rect.Y + this.Rect.Height));
            }
        }
    }
}
